
public class Exit {
	public static void main(String[] args) {
		final Thread mainThread = Thread.currentThread();

	     Runtime.getRuntime().addShutdownHook(new Thread() {
	         @Override
	         public void run() {
	             try {
	                 mainThread.interrupt();
	                 mainThread.join();
	             } catch (InterruptedException e) {
	                 e.printStackTrace();
	             }
	         }
	     });

	     while (!Thread.interrupted()) {
	         System.out.println("*");

	         try {
	             Thread.sleep(1000);
	         } catch (InterruptedException e) {
	             Thread.currentThread().interrupt();
	         }
	     }

	     System.out.println("Exit");		
	}
}
